package com.kclm.se.jcf;

import java.util.Comparator;
import java.util.Map.Entry;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;

public class TreeMapDemo {

	public static void main(String[] args) {
		//
		SortedMap<String, String> strMap = new TreeMap<>();
		//
		strMap.put("jack", "he is a student");
		strMap.put("ann", "she is a teacher");
		strMap.put("solo", "he is a engineer");
		strMap.put("peter", "he is a worker");
		//
		Set<Entry<String, String>> entrys = strMap.entrySet();
		//
		for(Entry<String,String> entry : entrys) {
			//
			System.out.printf("%s -> %s\n",entry.getKey(), entry.getValue());
		}
		System.out.println("-----------------  分割线 --------------------------");
		//
		//SortedMap<Teacher, Integer> teaMap = new TreeMap<>();
		//传入比较器
		Comparator<Teacher> ct = new MyComparator();
		SortedMap<Teacher, Integer> teaMap = new TreeMap<>(ct);
		//
		Teacher t1 = new Teacher("Zhang老师");
		Teacher t2 = new Teacher("Ye老师");
		Teacher t3 = new Teacher("Wang老师");
		Teacher t4 = new Teacher("Li老师");
		//
		teaMap.put(t1, 2);
		teaMap.put(t2, 1);
		teaMap.put(t3, 5);
		teaMap.put(t4, 3);
		//
		Set<Entry<Teacher, Integer>> es = teaMap.entrySet();
		for(Entry<Teacher, Integer> entry : es) {
			System.out.printf("%s -> %s\n", entry.getKey(), entry.getValue());
		}
	}
}
